Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(app): Create isMediaString util #3827

Merged
merged 1 commit into from
Mar 4, 2025
Merged

Conversation

ericakdiaz
Copy link
Contributor

@ericakdiaz ericakdiaz commented Mar 3, 2025

Description

  • Fixes WB-NNNNN
  • Fixes #NNNN

Creates a util for checking the metric type if it's a media string.

Testing

How was this PR tested?

See https://github.com/wandb/core/pull/27744

Summary by CodeRabbit

  • New Features
    • Enhanced media type validation for more consistent and reliable handling of media-related information throughout the application.

@ericakdiaz ericakdiaz requested a review from a team as a code owner March 3, 2025 21:31
Copy link
Contributor

coderabbitai bot commented Mar 3, 2025

Walkthrough

A new function isMediaString has been added to the media types module in the project. This function checks whether a given string is present in a predefined mediaStrings array and returns a type predicate to validate if it is a MediaString. The existing function isMediaCardType remains unaffected. This update enhances the type-checking capabilities for media types.

Changes

File Change Summary
weave-js/src/common/types/media.ts Added a new function isMediaString to check if a string is a member of mediaStrings array.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant F as isMediaString Function
    participant A as MediaStrings Array

    C->>F: Call isMediaString(type)
    F->>A: Check if type exists in mediaStrings
    A-->>F: Return match result (true/false)
    F-->>C: Return type predicate (boolean)
Loading

Poem

I'm a bunny coder, on a joyful spree,
Hopping through code with security key.
A new guard in place, checking strings with care,
Ensuring media types are always fair.
With each hop and byte, I leap in delight! 🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
weave-js/src/common/types/media.ts (1)

149-172: ⚠️ Potential issue

Type inconsistency between MediaString type and mediaStrings array.

The mediaStrings array includes 'partitioned-table' and 'joined-table' at lines 152-153, but these values are not included in the MediaString type definition (lines 126-147). This could lead to type inconsistencies, where isMediaString might return true for strings that aren't actually in the MediaString type.

export type MediaString =
  | 'data-frame'
  | 'table'
  | 'table-file'
+ | 'partitioned-table'
+ | 'joined-table'
  | 'images'
  | 'images/separated'
  | 'image-file'
  | 'videos'
  | 'video-file'
  | 'audio'
  | 'audio-file'
  | 'html'
  | 'html-file'
  | 'plotly'
  | 'plotly-file'
  | 'object3D'
  | 'object3D-file'
  | 'bokeh'
  | 'bokeh-file'
  | 'molecule'
  | 'molecule-file'
  | 'media'; // media is used for MessageMediaNotFound
🧹 Nitpick comments (2)
weave-js/src/common/types/media.ts (2)

229-231: Add JSDoc comment to improve documentation.

Consider adding a JSDoc comment to explain the function's purpose, similar to other functions in the file.

+/**
+ * Type predicate to check if a string is a valid MediaString type
+ * @param type - The string to check
+ * @returns boolean indicating if the string is a MediaString
+ */
export const isMediaString = (type: string): type is MediaString => {
  return _.includes(mediaStrings, type);
};

229-231: Consider validating the input parameter.

Add null/undefined check for the input parameter to make the function more robust, especially if it might be called with potentially undefined values.

export const isMediaString = (type: string): type is MediaString => {
-  return _.includes(mediaStrings, type);
+  return Boolean(type) && _.includes(mediaStrings, type);
};
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60b0926 and 60cd728.

📒 Files selected for processing (1)
  • weave-js/src/common/types/media.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{js,jsx,ts,tsx}`: Focus on architectural and logical i...

**/*.{js,jsx,ts,tsx}: Focus on architectural and logical issues rather than style (assuming ESLint is in place).
Flag potential memory leaks and performance bottlenecks.
Check for proper error handling and async/await usage.
Avoid strict enforcement of try/catch blocks - accept Promise chains, early returns, and other clear error handling patterns. These are acceptable as long as they maintain clarity and predictability.
Ensure proper type usage in TypeScript files.
Look for security vulnerabilities in data handling.
Don't comment on formatting if prettier is configured.
Verify proper React hooks usage and component lifecycle.
Check for proper state management patterns.

  • weave-js/src/common/types/media.ts
⏰ Context from checks skipped due to timeout of 90000ms (175)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, llamaindex)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, llamaindex)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, llamaindex)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, llamaindex)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, llamaindex)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, llamaindex)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, llamaindex)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, llamaindex)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, llamaindex)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, llamaindex)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, llamaindex)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, llamaindex)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, llamaindex)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, llamaindex)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, llamaindex)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
  • GitHub Check: WeaveJS Lint and Compile
  • GitHub Check: Trace nox tests (3, 13, pandas-test)
  • GitHub Check: Trace nox tests (3, 13, llamaindex)
  • GitHub Check: Trace nox tests (3, 13, trace_server)
  • GitHub Check: Trace nox tests (3, 13, trace)
  • GitHub Check: Trace nox tests (3, 12, scorers)
  • GitHub Check: Trace nox tests (3, 12, llamaindex)
  • GitHub Check: Trace nox tests (3, 12, trace_server)
  • GitHub Check: Trace nox tests (3, 12, trace)
  • GitHub Check: Trace nox tests (3, 11, scorers)
  • GitHub Check: Trace nox tests (3, 11, trace_server)
  • GitHub Check: Trace nox tests (3, 11, trace)
  • GitHub Check: Trace nox tests (3, 10, scorers)
  • GitHub Check: Trace nox tests (3, 10, trace_server)
  • GitHub Check: Trace nox tests (3, 10, trace)
  • GitHub Check: Trace nox tests (3, 9, scorers)
🔇 Additional comments (2)
weave-js/src/common/types/media.ts (2)

229-231: Good implementation of the new utility function.

The isMediaString function is a well-implemented TypeScript type predicate that follows the existing pattern of the isMediaCardType function. This will enhance type safety when checking for valid media string types.


229-231:

❓ Verification inconclusive

Verify usage in the codebase.

To ensure all call sites are properly using this new function, it would be good to verify any existing code that might need to be updated to use this function instead of ad-hoc checks.


🏁 Script executed:

#!/bin/bash
# Search for code that might be doing manual checks that could be replaced with isMediaString

echo "Looking for potential places to use the new isMediaString function..."

# Search for includes with mediaStrings
rg -t ts -t tsx "includes.*mediaStrings" --ignore-file=src/common/types/media.ts

# Search for other manual checks of media types
rg -t ts -t tsx "(type\s*===\s*['\"](images|audio|html|table|plotly|video|object3D|bokeh|molecule|data-frame))" \
   --ignore-file=src/common/types/media.ts

Length of output: 575


🏁 Script executed:

#!/bin/bash
# Corrected search for potential manual checks that could be replaced with isMediaString.
echo "Searching for potential places to use the new isMediaString function..."

# Using corrected ignore file path since the file is located at weave-js/src/common/types/media.ts
rg -g "*.ts" -g "*.tsx" "includes.*mediaStrings" --ignore-file=weave-js/src/common/types/media.ts

rg -g "*.ts" -g "*.tsx" "(type\s*===\s*['\"](images|audio|html|table|plotly|video|object3D|bokeh|molecule|data-frame))" --ignore-file=weave-js/src/common/types/media.ts

Length of output: 14305


Manual Verification of Media Type Checks Required

The new isMediaString implementation looks correct. However, our automated search for legacy ad-hoc checks (using inclusion or strict equality against media type strings) yielded inconclusive results due to regex parsing issues. Please manually verify the following:

  • Confirm that no call sites are performing manual checks against media types (e.g., using direct comparisons or includes on mediaStrings) that should instead use isMediaString.
  • Review components and functions related to media handling to ensure consistency in media type validation.

@circle-job-mirror
Copy link

circle-job-mirror bot commented Mar 3, 2025

@ericakdiaz ericakdiaz merged commit e577d26 into master Mar 4, 2025
132 checks passed
@ericakdiaz ericakdiaz deleted the ericakdiaz/is-media-string branch March 4, 2025 19:29
@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants